package com.blue.waffle.iwc.domains.helpers;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * DAO (Data Access Object) interface for the domain models.
 * @author Wenbin
 *
 * @param <T> - the domain model type
 */
public interface DataHelper<T> {

	/**
	 * Simple Select all operation from the database of the specific defined type<{@link T }>.
	 * @return - the list of objects found in the result
	 * @throws SQLException
	 */
	public List<T> selectAll() throws SQLException;
	
	/**
	 * Simple Select operation by taking a raw parameterized sql and the corresponding parameters.
	 * @param sql - the raw sql
	 * @param para - the list of paramenters
	 * @return -the list of objects found in the result
	 * @throws SQLException
	 */
	public List<T> select(String sql,Object[] para) throws SQLException;
	
	/**
	 * Simple Insert operation.
	 * @param model
	 * @throws SQLException
	 */
	public void insert(T model) throws SQLException;
	//public void insertBatch(List<T> models) throws SQLException;
	
	/**
	 * Simple Update operation.
	 * @param model
	 * @throws SQLException
	 */
	public void update(T model) throws SQLException;
	//public void updateBatch(List<T> models) throws SQLException;
	
	/**
	 * Simple Delete operation.
	 * @param model
	 * @throws SQLException
	 */
	public void delete(T model) throws SQLException;
	
	/**
	 * Simple count operation which returns a number of all records found in the target type table by running a raw query.
	 * @param sql
	 * @return
	 * @throws SQLException
	 */
	public int count(String sql) throws SQLException;
	
	/**
	 * Simple count all operation which returns a number of all records found in the target type table.
	 * @return
	 * @throws SQLException
	 */
	public int count() throws SQLException;
	
	/**
	 * A utility method that parse the raw query result set into its associated type.
	 * @param resultSet
	 * @return
	 * @throws SQLException
	 */
	public T getObject(ResultSet resultSet) throws SQLException;
	
	/**
	 * Checks if the current database connection is closed.
	 * @return
	 * @throws SQLException
	 */
	public boolean isClosed() throws SQLException;
	
	/**
	 * Gracefully closes the current database connection.
	 * @throws SQLException
	 */
	public void close() throws SQLException;
	
	/**
	 * Sets the current database connection to use.
	 * @param connection
	 */
	public void setConnection(Connection connection);
	
}
